package com.ctgu.computer.controller.user;

import com.ctgu.computer.common.FailedMessage;
import com.ctgu.computer.domain.dto.PageQueryDTO;
import com.ctgu.computer.domain.dto.ReportSendDTO;
import com.ctgu.computer.domain.result.PageResult;
import com.ctgu.computer.domain.result.Result;
import com.ctgu.computer.domain.vo.ImagePaths;
import com.ctgu.computer.service.ReportService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController("用户举报相关接口")
@RequestMapping("/sys/user/report")
@RequiredArgsConstructor
@Tag(name = "用户举报相关接口")
public class ReportController {
    private final ReportService reportService;

    @Operation(summary = "分页查询当前用户的举报信息")
    @PostMapping("/list")
    public Result<PageResult> getCurrentUserReport(@RequestBody PageQueryDTO pageQueryDTO){
        return Result.success(reportService.getCurrentUserReport(pageQueryDTO));
    }

    @Operation(summary = "发送举报信息")
    @PostMapping("/send")
    public Result sendReportInfo(@RequestBody ReportSendDTO reportSendDTO){
        reportService.addReportInfo(reportSendDTO);
        return Result.success();
    }

    @Operation(summary = "举报图片上传")
    @PostMapping("/upload")
    public Result<ImagePaths> reportUpload(@RequestParam MultipartFile[] files){
        for (MultipartFile file : files) {
            if(!file.isEmpty()){
                if(!file.getOriginalFilename().contains(".png")&&!file.getOriginalFilename().contains(".jpg")){
                    return Result.error(FailedMessage.ONLY_IMAGE_TYPE);
                }
            }
        }
        return Result.success(reportService.upload(files));
    }

    @Operation(summary = "撤回举报消息")
    @GetMapping("/recall/{reportId}")
    public Result recallReportedInfo(@PathVariable Integer reportId){
        reportService.deleteReportInfo(reportId);
        return Result.success();
    }
}
